<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/icon.css" />

<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.9.1.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
<title>老师个人信息</title>
</head>
<script type="text/javascript">
$(function() {
	
	//展现当前老师的学生信息
	$("#studentxinxi").datagrid({
		url:'studentxinxi.json',
		columns:[[   
		          {field:'ck',checkbox:true},
		          {field:'sid',title:'学号',width:100},    
		          {field:'sname',title:'姓名',width:100},    
		          {field:'ssex',title:'性别',width:100},    
		          {field:'sage',title:'年龄',width:100},    
		          {field:'saddress',title:'地址',width:100},    
		          {field:'spnumber',title:'联系电话',width:100},    
		          {field:'stime',title:'入学时间',width:100},    
		          {field:'bid',title:'班级',width:100}
		      ]] ,
		      rownumbers:true,
		      pagination:true,
		      pagePosition:'bottom',
		      pageSize:3,
		      pageList:[3,6,9],
		      toolbar: [{
		      	
		     // ----------------------------修改------------------------------------
		      	iconCls:'icon-edit',
		      	text:'修改学生信息',
		  		handler: function(){
		  			$('#ssex').combobox({ 
					    panelHeight:50
					}); 
		  			$('#stime').datebox({    
		  				width:100   
		  			});  


		  				var  stus = $('#studentxinxi').datagrid('getSelections');    
		  				if(stus.length==1){
		  					$("#uptStudent").dialog("open").dialog('setTitle', '修改学生信息'); 
		  					$('#sage').numberbox('setValue',stus[0].sage );
		  					$('#ssex').combobox('setValue',stus[0].ssex );
							$("#sname").val(stus[0].sname);
							$("#saddress").val(stus[0].saddress);
							$('#spnumber').numberbox('setValue',stus[0].spnumber );
							
							//只能读取日期格式的数据 YYYY-MM-DD
							$('#stime').datebox('setValue', stus[0].stime);
	  					
		  					$("#sve").linkbutton({
		  						onClick:function(){						
		  							var sname = $("#sname").val();
		  							var sage = $('#sage').numberbox('getValue');
		  							var ssex =$('#ssex').combobox('getText');
		  							var saddress =$("#saddress").val();
		  							var spnumber = $('#spnumber').numberbox('getValue');
		  							var stime =$('#stime').datebox('getText');
		  							var sid =stus[0].sid;
		  							$.ajax({
		  								url:'uptStudent',
		  								type:'post',
		  								data:{'sid':sid,'sname':sname,'sage':sage,'ssex':ssex,'saddress':saddress,'spnumber':spnumber,'stime':stime},
		  								dataType:'text',
		  								success:function(xx){
		  								if(xx=="0"){
		  									$.messager.alert('error','修改失败！','info');
		  								}else{
		  									$.messager.alert('信息','修改成功','info');	
		  									$("#uptStudent").dialog("close");		
		  				     				$('#studentxinxi').datagrid('reload');
		  								}
		  						}
		  					})
		  						}
		  					})
		  			
		  				}else{
		  					$.messager.confirm('error','请选择要修改的学生',function(r){    
		  					    if (r){    
		  					    	$('#studentxinxi').datagrid('uncheckAll');    
		  					    }    
		  					});  
		  				}		  				
		  			}
		  	}] 
	});
	//判断年龄在0——150之间
	$("input",$("#sage").next("span")).blur(function(){
		var sage = $('#sage').numberbox('getValue');
		if(sage<=0||sage>=150){
		    	$("#rsage").show();
		    	$("#sve").linkbutton({ 
		    		disabled:true
		    	})
		}else{
			$("#rsage").hide();
			$("#sve").linkbutton({ 
	    		disabled:false
			})
		}
	    });
	//判断电话号码是否正确
	$("input",$("#spnumber").next("span")).blur(function(){
		var spnumber =  $('#spnumber').numberbox('getValue');
		if(spnumber<=10000000000||spnumber>=19999999999){
		    	$("#rspnumber").show();
		    	$("#sve").linkbutton({ 
		    		disabled:true
		    	})
		}else{
			$("#rspnumber").hide();
			$("#sve").linkbutton({ 
	    		disabled:false
			})
		}
	    })

	
})
</script>
<body>
<table id="studentxinxi" >
</table> 
<!------------------------------------- 修改 ----------------------------------------->
<div id="uptStudent" class="easyui-dialog"  closed="true" buttons="#dlg1-buttons "  > 
		<div  style="width: 300px;height: 250px;margin-top: 50px;margin-left:80px">
              姓名<input id="sname" name="sname" class="easyui-validatebox"  /><br>    
              年龄<input id="sage" name="sage"  class="easyui-numberbox"  data-options="precision:0"/>
		<span id="rsage"  style="font-size:xx-small;display:none;">年龄在0—150岁之间!</span><br>
              性别<select id="ssex" class="easyui-combobox" name="ssex" style="width:70px;">   
    <option value="请选择">男</option>   
    <option>女</option> 
</select><br>
               地址<input id="saddress" name="saddress" class="easyui-validatebox"  /><br>
               电话<input id="spnumber" name="spnumber" class="easyui-numberbox"  data-options="precision:0" />
               <span id="rspnumber"  style="font-size:xx-small;display:none;">请输入正确的电话号码!</span><br>
            入学时间<input id="stime" name="stime" class="easyui-validatebox"  style="width:150px;"/> <br>
      </div>
       <div id="dlg1-buttons">
        <button id="sve"  class="easyui-linkbutton"  iconcls="icon-save">确认修改</button>
        <a id="cancl" class="easyui-linkbutton" onclick="javascript:$('#uptStudent').dialog('close')"
         iconcls="icon-cancel">取消</a>
        </div>
</div>

</body>
</html>